package cn.gjxblog.mq.custom;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;

import java.io.IOException;

/**
 * @author gjx
 * @version v1.0
 * @Description 自定义消费者
 * @date 2019/7/4 16:03
 */
public class CustomConsumer extends DefaultConsumer {
    /**
     * Constructs a new instance and records its association to the passed-in channel.
     *
     * @param channel the channel to which this consumer is attached
     */
    public CustomConsumer(Channel channel) {
        super(channel);
    }

    @Override
    public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
        super.handleDelivery(consumerTag, envelope, properties, body);
        System.out.println("----------consume message-----------");
        System.out.println("--consumerTag:"+consumerTag);
        System.out.println("--properties:"+properties);
        System.out.println("--envelope:"+envelope);
        System.out.println("--body:"+new String(body));
    }
}
